package com.ruoyi.web.hnsdsa.util;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.extra.compress.CompressUtil;
import cn.hutool.extra.compress.archiver.Archiver;
import com.ruoyi.web.hnsdsa.domain.SignStudentApply;
import org.apache.commons.compress.archivers.ArchiveStreamFactory;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class DownFileUtil {

    public static void main(String[] args) {


        List<File> x = new ArrayList<>();
        x.add(FileUtil.file("d:/console.log"));

//        String compress = compress(x);
    }


    /**
     * 压缩算法
     *
     * @return 文件路径
     */
    public static String compress(List<String> studentFilesPath) {

        File file = FileUtil.file("D:/joinStudent/Student.zip");
        Archiver archiver = CompressUtil.createArchiver(CharsetUtil.CHARSET_UTF_8, ArchiveStreamFactory.ZIP, file);
        studentFilesPath.forEach(item -> {
            archiver.add(FileUtil.file(item));
        });
        archiver.finish().close();

        return file.getPath();
    }

    /**
     * 生成所有学生的照片
     * @param studentApplies
     * @return
     */
    public static  List<String> bornFiles(List<SignStudentApply> studentApplies) {
        List<String> imageUrls = new ArrayList<>(studentApplies.size());
        studentApplies.forEach(item -> {
            imageUrls.add(item.getStudentPhtot());
        });
        return imageUrls;
    }


}
